#pragma once
#include <iostream>
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator() {}
    Response Execute(const Request &request)
    {
        // 我们拿到都是结构化数据
        Response response;
        switch (request.Oper())
        {
        case '+':
            response.SetResult(request.X() + request.Y());
            break;
        case '-':
            response.SetResult(request.X() - request.Y());
            break;
        case '*':
            response.SetResult(request.X() * request.Y());
            break;
        case '/':
            if (request.Y() == 0)
            {
                response.SetResult(1); // code为1表示除数为0
            }
            else
            {
                response.SetResult(request.X() / request.Y());
            }
            break;
        case '%':
            if (request.Y() == 0)
            {
                response.SetResult(2); // code为1表示:%为0
            }
            else
            {
                response.SetResult(request.X() % request.Y());
            }
            break;
        default:
            response.SetResult(3); // code为3表示操作符不支持
            break;
        }
        return response;
    }
    ~Calculator() {}

private:
};